package com.healthcarex.hip.saas.security.service.impl;

import com.healthcarex.hip.saas.security.model.SysRoleResource;
import com.healthcarex.hip.saas.security.service.IRoleResourceService;
import com.healthcarex.hip.saas.mybatis.service.impl.BaseServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @author chenpan
 * @ClassName: RoleResourceServiceImpl
 * description:
 * @date 2018-04-02 17:57
 */
@Service
public class RoleResourceServiceImpl extends BaseServiceImpl<SysRoleResource> implements IRoleResourceService {

    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    @CacheEvict(value = {"authority", "resource:tree", "permission","urlPermission"}, allEntries = true)
    public void deleteRoleResourcesByRoleId(String roleIds) {
        List<String> list = Arrays.asList(roleIds.split(","));
        this.batchDelete(list, "roleId", SysRoleResource.class);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
    @CacheEvict(value = {"authority", "resource:tree", "permission","urlPermission"}, allEntries = true)
    public void deleteRoleResourceByResourceId(String resourceIds) {
        List<String> list = Arrays.asList(resourceIds.split(","));
        this.batchDelete(list, "resourceId", SysRoleResource.class);
    }
}
